package com.example.liao.day8_22;

import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;

import java.util.ArrayList;

public class MainActivity extends AppCompatActivity {


    private int[] icon = {R.mipmap.img1, R.mipmap.img2, R.mipmap.img3, R.mipmap.img4};
    private ViewPager vpshhow;
    private ArrayList<View> views;
    private MyAdapter myAdapter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        initview();//初始化视图
        initdata();//初始化数据
        show();//初始化下面四个
    }

    private void initview() {
        vpshhow = findViewById(R.id.vp_show);
        views = new ArrayList<>();
        myAdapter = new MyAdapter(views);
    }

    private void initdata() {
        for (int i = 0; i < icon.length; i++) {
//            ImageView imageView = new ImageView(this);
//            ViewPager.LayoutParams  layoutParams = new ViewPager.LayoutParams();
            ImageView inflate = (ImageView) LayoutInflater.from(this).inflate(R.layout.view_page_item_image_view, vpshhow, false);
            inflate.setImageResource(icon[i]);
//            inflate.setLayoutParams(layoutParams);
            views.add(inflate);
        }
        vpshhow.setAdapter(myAdapter);
    }
    
    private void show() {


    }

    public void go1(View view) {
        //指定ViewPager切换到第几页,参数一:页码,参数二:是否开启切换动画
        vpshhow.setCurrentItem(0, false);
    }
}
